package com.qf.smartplatform.controller;

import com.qf.smartplatform.dto.Result;
import com.qf.smartplatform.pojo.Scene;
import com.qf.smartplatform.pojo.User;
import com.qf.smartplatform.service.SceneService;
import com.qf.smartplatform.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * projectName:day12_27_Test
 * author:guoLei
 * time:2022/1/4 9:58
 * description:
 */
@RestController
@RequestMapping("/scenes")
public class SceneController {
    private SceneService sceneService;

    @Autowired
    public void setSceneService(SceneService sceneService) {
        this.sceneService = sceneService;
    }

    @PostMapping("/scene")
    public Result addScene(@RequestBody Scene scene) {
        sceneService.addScene(scene);
        return Result.setOK();
    }

    @GetMapping("/scenes")
    public Result findAllSceneByUser() {
        User user = SecurityUtils.getUser();
        List<Scene> sceneList = sceneService.findByUserId(user.getUId());
        return Result.setOK(sceneList);
    }

}

